package com.hnit.camellia.service.impl;

import com.hnit.camellia.entity.Category;
import com.hnit.camellia.entity.Goods;
import com.hnit.camellia.entity.MapData;
import com.hnit.camellia.entity.ScatterData;
import com.hnit.camellia.entity.vo.CategoryVo;
import com.hnit.camellia.mapper.CategoryMapper;
import com.hnit.camellia.mapper.GoodsMapper;
import com.hnit.camellia.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Service
public class CategoryServiceImpl implements CategoryService {


    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private GoodsMapper goodsMapper;
    /**
     * 查询所有分类
     * @return
     */
    @Override
    public List<CategoryVo> selectCategoryVoList() {
        List<Category> categoryList = categoryMapper.selectCategoryList();
        List<CategoryVo> categoryVoList = new ArrayList<>();
        for(Category category : categoryList){
            CategoryVo categoryVo = new CategoryVo();
            categoryVo.setId(category.getId());
            categoryVo.setName(category.getName());
            categoryVo.setTypeId(category.getTypeId());
            List<Goods> goods = goodsMapper.selectGoodsByCategoryId(category.getId());
            categoryVo.setGoods(goods);
            categoryVoList.add(categoryVo);

        }


        return categoryVoList;
    }




    @Override
    public Category selectCategory() {
        return categoryMapper.selectCategory();
    }
}
